﻿/*-------------------------------------
//
//Copyright (C) 2007 开发二组 版权所有。
//
//文件名：CategoryManage.ascx.cs
//
//文件功能描述： 商品类别管理
// 
//创建标识：2007.11.22 王林进
//创建描述：
//
//修改标识：2007.12.04王林进
//修改描述：更改搜索
------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using JXMSTC.SmartBusiness.BFL;
using localhost;
/// <summary>
/// 商品类别管理
/// </summary>
///<remarks >
/// 创建时间：2007-11-16 
///</remarks>
public partial class UserControls_CategoryManage : System.Web.UI.UserControl
{
    //实例两个数据集用以分页
    private  DataSet dsUpperCategory = new DataSet();

    private  DataSet dsLowerCategory = new DataSet();

    ProductService categoryManage = new ProductService();

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {           
            ////取得大类别列表 
            //GetUpperCategory(string.Empty ,string .Empty );

            ////取得小类别列表
            //GetLowerCategory(string .Empty ,string .Empty );
            int iPageSize = 10;
            int iPageIndex = 1;
            dsUpperCategory = categoryManage.GetUpperCategoryForPaging(iPageSize, iPageIndex,string.Empty ,string.Empty );

            this.GridViewBindUpperCategory (dsUpperCategory);

            this.hdfUpperCategoryRows.Value = categoryManage.GetUpperCategoryRows(string.Empty, string.Empty).ToString ();
                    
            this.PagingUpperCateogy (iPageSize, iPageIndex);


            dsLowerCategory = categoryManage.GetLowerCategoryForPaging(iPageSize, iPageIndex, string.Empty, string.Empty);

            this.GridViewBindLowerCategory (dsLowerCategory);

            this.hdfLowerCategoryRows.Value = categoryManage.GetLowerCategoryRows(string.Empty, string.Empty).ToString ();          

            this.PagingLowerCategory (iPageSize, iPageIndex);

        }
        
    }

    ///// <summary>
    ///// 大类别列表数据绑定
    ///// </summary>
    ///// <param name="sender">事件源</param>
    ///// <param name="e">事件参数</param>
    //void category_GetUpperCategoryListCompleted(object sender, GetUpperCategoryListCompletedEventArgs e)
    //{
    //    //绑定数据源到dataSet中
    //    dataSet = e.Result;

    //    //调用绑定函数
    //    GridviewBind(dataSet);
    //}

    ///// <summary>
    ///// 小类别列表数据绑定
    ///// </summary>
    ///// <param name="sender">事件源</param>
    ///// <param name="e">事件参数</param>
    //void lowerCategory_GetLowCategoryListCompleted(object sender, GetLowCategoryListCompletedEventArgs e)
    //{
    //    //绑定数据源到dataSet中
    //    dataSet2 = e.Result;

    //    //调用绑定函数
    //    SmallGridviewBind(dataSet2);
    //}
      
    ///// <summary>
    ///// 异步调用获得大类别列表
    ///// </summary>
    ///// <param name="strUpperName">大类别名称</param>
    ///// <param name="strUpperStatus">大类别状态</param>
    //public void GetUpperCategory(string strUpperName,string strUpperStatus)
    //{
    //    //实例化一个服务
    //    ProductService category = new ProductService();

    //    category.GetUpperCategoryListCompleted += new GetUpperCategoryListCompletedEventHandler(category_GetUpperCategoryListCompleted);
       
    //    //异步调用获得大类别列表
    //    category.GetUpperCategoryListAsync();

    //}

    
    ///// <summary>
    ///// 异步调用获得小类别列表
    ///// </summary>
    ///// <param name="strLowerName">小类别名称</param>
    ///// <param name="strLowerStatus">小类别状态</param>
    //public void GetLowerCategory(string strLowerName,string strLowerStatus)
    //{
    //    //实例化一个服务
    //    ProductService lowerCategory = new ProductService();

    //    lowerCategory.GetLowCategoryListCompleted += new GetLowCategoryListCompletedEventHandler(lowerCategory_GetLowCategoryListCompleted);

    //    //异步调用获得小类别列表
    //    lowerCategory.GetLowCategoryListAsync();
       

    //}




    /// <summary>
    /// 点击GridView控件的按钮时发生的操作
    /// </summary>
    /// <param name="sender">事件源</param>
    /// <param name="e">事件参数</param>
        protected void gdvBigCategory_RowCommand(object sender, GridViewCommandEventArgs e)
        {   
            //点击管理按钮时页面转向类别添加页。  
            if(e.CommandName == "Manage")
            {
                //取得选中行的索引。
                int index = Convert.ToInt32(e.CommandArgument);

                //取得选中行中UppreCategoryID的值。
                string strUpperCategoryID = gdvBigCategory.DataKeys[index].Value.ToString();
                this.lblUpperCategoryID.Text  = strUpperCategoryID;
                //取得选中行中UppreCategoryID的名称 
                string strUpperCategoryName = gdvBigCategory.DataKeys[index].Values[1].ToString();
                this.lblUpperCategoryName.Text  = strUpperCategoryName;

                //Response.Redirect(@"~\CategoryAdd.aspx?UpperCategoryID=" + strUpperCategoryID + "&UpperCategoryName=" + strUpperCategoryName);
                Server.Transfer(@"~\StoreKeeper\CategoryAdd.aspx");
            }

            //点击查看按钮时显示该大类别中包含的所有小类别。
            else if(e.CommandName =="Select")
            {
                //取得选中行的索引。
                int index = Convert.ToInt32(e.CommandArgument);

                //取得选中行中UppreCategoryID的值。
                string strUpperCategoryID = gdvBigCategory.DataKeys [index].Value .ToString ();
                this.hdfUpperCategoryID.Value = strUpperCategoryID;
                int iPageSize = 10;
                int iPageIndex= 1;

                ////把选择的
                //this.ViewState ["categoryName"] = gdvBigCategory.DataKeys[index].Values[1].ToString();

                ////实例化一个服务
                //ProductService lookLowerCategory = new ProductService();

                this.GridViewBindLowerCategory (categoryManage.GetLowerCategoryByUpperCategoryIDForPaging (iPageSize ,iPageIndex ,strUpperCategoryID ));
                this.hdfLowerCategoryRows.Value = categoryManage.GetLowerCategoryByUpperCategoryIDRows(strUpperCategoryID).ToString ();
                this.PagingLowerCategory(iPageSize, iPageIndex);

                //lookLowerCategory.GetLowCategoryListByUpperCategoryIDCompleted += new GetLowCategoryListByUpperCategoryIDCompletedEventHandler(lookLowerCategory_GetLowCategoryListByUpperCategoryIDCompleted);

                ////异步调用获得查看的所有小类别。
                //lookLowerCategory.GetLowCategoryListByUpperCategoryIDAsync(strUpperCategoryID);

                if (this.CategoryManageMultiView.ActiveViewIndex == 0)
                {    //      
                    CategoryManageMultiView.ActiveViewIndex += 1;
                }        
            }

            // 点击删除时所执行的操作。
            else if (e.CommandName == "Categorydelete")
            {
                //ProductService deleteUpperCategory = new ProductService();
                try
                {   //取得选中行的索引。
                    int index = Convert.ToInt32(e.CommandArgument);
                    //取得选中行中UppreCategoryID的值
                    string strCategoryID = gdvBigCategory .DataKeys[index].Value .ToString ();
                    //逻辑删除该类别,成功返回true,反之false.
                    bool result =categoryManage.DeleteUpperCategory(strCategoryID);

                    if (result == true)//如果删除成功 更新GridView
                    {
                       
                        //获得textBox中的大类别名称
                        string strUpperCategoryName = this.txtCategoryUpperName .Text.Trim();

                        //获得dropDownList中的大类别状态
                        string strUpperCategoryStatus = this.dropUpperStatus.SelectedValue;

                        int iPageSize = 10;
                        int iPageIndex = 1;

                        
                        if (strUpperCategoryStatus == "全部")
                        {
                            //如果为"全部'则把其状态改为空
                            strUpperCategoryStatus = string.Empty;
                            this.GridViewBindUpperCategory(categoryManage.GetUpperCategoryForPaging(iPageSize, iPageIndex,strUpperCategoryName ,strUpperCategoryStatus ));
                            this.hdfUpperCategoryRows.Value = categoryManage.GetUpperCategoryRows(strUpperCategoryName ,strUpperCategoryStatus ).ToString ();
                            this.PagingUpperCateogy(iPageSize, iPageIndex);

                        }
                     
                        ////实例化一个数据集ds
                        //DataSet ds=new DataSet ();
                        
                        //if (strUpperCategoryStatus != string.Empty)
                        //{
                        //    bool blUpperStatus = false;                           
                        //    //获得要查询大类别的大类别数据集
                        //    ds = deleteUpperCategory.GetUpperCategory(strUpperCategoryName, blUpperStatus);
                        //}
                        else
                        {
                            ////获得全部大类别列表数据集
                            //ds = deleteUpperCategory.GetUpperCategoryList();

                            this.GridViewBindUpperCategory(categoryManage.GetUpperCategoryForPaging(iPageSize, iPageIndex,strUpperCategoryName ,strUpperCategoryStatus ));
                            this.hdfUpperCategoryRows.Value = categoryManage.GetUpperCategoryRows(strUpperCategoryName, strUpperCategoryStatus).ToString();
                            this.PagingUpperCateogy(iPageSize, iPageIndex);
                        }
                        ////把数据源给GridView ,绑定数据
                        // gdvBigCategory.DataSource = ds;
                        // gdvBigCategory.DataBind();
                    }                
                }
                catch (Exception ex)
                {               }  
            }
        }


    ///// <summary>
    ///// 处理返回值，绑定并显示大类别中包含的所有小类别 
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //void lookLowerCategory_GetLowCategoryListByUpperCategoryIDCompleted(object sender, GetLowCategoryListByUpperCategoryIDCompletedEventArgs e)
    //{
    //    dataSet2 = e.Result;//绑定数据源到dataSet中

    //    SmallGridviewBind(dataSet2);//调用绑定函数

    //}
    /// <summary>
    /// 处理小类别GridView中的操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
        protected void gdvSmallCategory_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //点击管理按钮时页面转向类别添加页。 
            if (e.CommandName == "Manage")
            {
                //取得选中行的索引。
                int index = Convert.ToInt32(e.CommandArgument);

                //取得选中行中LowerCategoryID的值
                string strLowerCategoryID = gdvSmallCategory.DataKeys[index].Value.ToString();
                this.lblLowerCategoryID.Text  = strLowerCategoryID;
                //获得选中行的LowerCategoryName 
                string strLowerCategoryName =gdvSmallCategory .DataKeys [index].Values [1].ToString();
                this.lblLowerCategoryName.Text = strLowerCategoryName;

                this.lblFatherCategoryID .Text= gdvSmallCategory.DataKeys[index].Values[2].ToString();
 
                //Response.Redirect(@"~\CategoryAdd.aspx?LowerCategoryID=" + strLowerCategoryID +"&LowerCategoryName=" + strLowerCategoryName );
                Server.Transfer(@"~\StoreKeeper\CategoryAdd.aspx");
            }
            // 点击删除时所执行的操作.
            else if (e.CommandName == "LogicalDelete")
            {
                //ProductService deleteLowerCategory = new ProductService();
                try
                {
                    int index = Convert.ToInt32(e.CommandArgument);//取得选中行的索引。

                    //取得选中行中LowerCategoryID的值
                    string strLowerCategoryID = gdvSmallCategory.DataKeys[index].Value.ToString();
                    //逻辑删除该类别,成功返回true,反之false.
                    bool result = categoryManage.DeleteLowCategory(strLowerCategoryID);

                    int iPageSize = 10;
                    int iPageIndex = 1;


                    if (result == true)//如果删除成功 更新GridView
                    {

                        ////获得小类别名称
                        //string strLowerCategoryName = gdvSmallCategory.DataKeys[index].Values[1].ToString(); 
                        //this.txtCategoryLowerName.Text = strLowerCategoryName ;
                        if (this.hdfUpperCategoryID.Value != string.Empty)
                        {
                            string strUpperCategoryID = this.hdfUpperCategoryID.Value;
                            this.GridViewBindLowerCategory(categoryManage.GetLowerCategoryByUpperCategoryIDForPaging(iPageSize, iPageIndex, strUpperCategoryID));
                            this.hdfLowerCategoryRows.Value = categoryManage.GetLowerCategoryByUpperCategoryIDRows(strUpperCategoryID).ToString();
                            this.PagingLowerCategory(iPageSize, iPageIndex);
                        }
                        else
                        {
                            //获得小类别的状态
                            string strLowerCategoryStatus = this.dropLowerStatus.SelectedValue;

                            string strLowerCategoryName = this.txtCategoryLowerName.Text.Trim();

                            if (strLowerCategoryStatus == "全部")
                            {
                                //更改小类别的状态
                                strLowerCategoryStatus = string.Empty;
                                this.GridViewBindLowerCategory(categoryManage.GetLowerCategoryForPaging(iPageSize, iPageIndex,strLowerCategoryName ,strLowerCategoryStatus ));
                                this.hdfLowerCategoryRows.Value = categoryManage.GetLowerCategoryRows(strLowerCategoryName, strLowerCategoryStatus).ToString();
                                this.PagingLowerCategory(iPageSize, iPageIndex);
                            }

                            ////实例化一个数据集ds
                            //DataSet ds = new DataSet();

                            //if (strLowerCategoryStatus != string.Empty || txtCategoryLowerName .Text !=string .Empty )
                            //{
                            //    bool blLowerStatus = false;

                            //    //获得要查询的小类别的小类别数据集
                            //    ds = deleteLowerCategory.GetLowerCategory(strLowerCategoryName, blLowerStatus);
                            //}
                            else
                            {
                                ////获得全部小类别列表数据集
                                //ds = deleteLowerCategory.GetLowCategoryList();
                                this.GridViewBindLowerCategory(categoryManage.GetLowerCategoryForPaging(iPageSize, iPageIndex, strLowerCategoryName, strLowerCategoryStatus));
                                this.hdfLowerCategoryRows.Value = categoryManage.GetLowerCategoryRows(strLowerCategoryName, strLowerCategoryStatus).ToString();
                                this.PagingLowerCategory(iPageSize, iPageIndex);
                            }
                            ////把数据源给GridView,数据绑定
                            //gdvSmallCategory.DataSource = ds;
                            //gdvSmallCategory.DataBind();
                        }
                    }
                }
                catch (Exception ex)
                { }
            }
       }
 

    /// <summary>
    /// 按大类别查找商品信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnUpperSearch_Click(object sender, ImageClickEventArgs e)
    {

    
        //this.lblUpperMessage .Text = string .Empty ;
        ////把大类别名称相对应的验证控件在查询类别时置为可用。
        //this.RequiredFieldValidator1.Visible = true;
        //获取大类别名称
        string strUpperName = this.txtCategoryUpperName.Text.Trim() ;
        int iPageSize =10;
        int iPageIndex =1;

        if (dropUpperStatus.SelectedValue == "全部")
        {   
            ////把名称置为空
            //strUpperName = string.Empty;
            //把状态置为空
            string strUpperStatus = string.Empty;
            ////获得大类别的列表
            //GetUpperCategory(strUpperName, strUpperStatus);
            
            this.GridViewBindUpperCategory (categoryManage.GetUpperCategoryForPaging(iPageSize, iPageIndex, strUpperName, strUpperStatus));
            this.hdfUpperCategoryRows.Value  = categoryManage.GetUpperCategoryRows(strUpperName, strUpperStatus).ToString ();
            this.PagingUpperCateogy(iPageSize, iPageIndex);
        }
        else
        {   //获取用户要查询商品的状态
            string strUpperStatus = this.dropUpperStatus.SelectedValue;
            ////调用查询大类别函数
            //SearchGetUpperCategory(strUpperName, blUpperStatus);
            this.GridViewBindUpperCategory(categoryManage.GetUpperCategoryForPaging(iPageSize, iPageIndex, strUpperName, strUpperStatus));
            this.hdfUpperCategoryRows.Value = categoryManage.GetUpperCategoryRows(strUpperName, strUpperStatus).ToString();
            this.PagingUpperCateogy(iPageSize, iPageIndex);
        }
        
    }

    ///// <summary>
    ///// 根据条件查询大类别
    ///// </summary>
    ///// <param name="strUpperName">大类别名称</param>
    ///// <param name="blUpperStatus">大类别状态</param>
    //public void SearchGetUpperCategory(string strUpperName, bool blUpperStatus)
    //{
    //    //实例化一个服务
    //    ProductService UPCategoryManage = new ProductService();

    //    UPCategoryManage.GetUpperCategoryCompleted += new GetUpperCategoryCompletedEventHandler(UPCategoryManage_GetUpperCategoryCompleted);

    //    //异步调用得到大类别函数
    //    UPCategoryManage.GetUpperCategoryAsync(strUpperName, blUpperStatus);
    //} 

    ///// <summary>
    ///// 对返回结果进行绑定
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //void UPCategoryManage_GetUpperCategoryCompleted(object sender, GetUpperCategoryCompletedEventArgs e)
    //{
    //    //如果纪录为零，则提示用户商品不存在，反之绑定并显示数据。
    //    if (e.Result.Tables[0].Rows.Count != 0)
    //    {
    //        //绑定数据源到dataSet中
    //        dataSet = e.Result;
    //        //调用绑定函数
    //        GridviewBind(dataSet);
    //    }
    //    else
    //    {
    //        this.lblUpperMessage.Text = "没有你查找的商品类别";
            
    //    }
     
    //}


    /// <summary>
    /// 按小类别查找商品信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnLowerSearch_Click(object sender, ImageClickEventArgs e)
    {

        //this.lblLowerMessage.Text = string.Empty;
        ////把小类别名称相对应的验证控件在查询类别时置为可用。
        //this.RequiredFieldValidator2.Visible = true;
        ////把大类别名称相对应的验证控件在查询小类别时置为不可用。
        //this.RequiredFieldValidator1.Visible = false;
        //获取小类别名称
        string strLowerName = this.txtCategoryLowerName.Text.Trim();
        int iPageSize=10;
        int iPageIndex =1;

        if (dropLowerStatus.SelectedValue == "全部")
        {  
            ////把名称置为空
            //strLowerName = string.Empty;
            //把状态置为空
            string strLowerStatus = string.Empty;
            ////获得小类别的列表
            //GetLowerCategory(strLowerName, strLowerStatus);
            this.GridViewBindLowerCategory (categoryManage .GetLowerCategoryForPaging (iPageSize ,iPageIndex ,strLowerName ,strLowerStatus ));
            this.hdfLowerCategoryRows.Value = categoryManage.GetLowerCategoryRows(strLowerName, strLowerStatus).ToString();
            this.PagingLowerCategory(iPageSize, iPageIndex);
        }
        else
        {   //获取用户要查询商品的状态
           string strLowerStatus = this.dropLowerStatus.SelectedValue;

            ////调用查询小类别函数
            //SearchGetLowerCategory(strLowerName, blLowerStatus);
           this.GridViewBindLowerCategory(categoryManage.GetLowerCategoryForPaging(iPageSize, iPageIndex, strLowerName, strLowerStatus));
           this.hdfLowerCategoryRows.Value = categoryManage.GetLowerCategoryRows(strLowerName, strLowerStatus).ToString();
           this.PagingLowerCategory(iPageSize, iPageIndex);
        }
    }

    ///// <summary>
    ///// 根据条件查询小类别
    ///// </summary>
    ///// <param name="strLowerName">小类别名称</param>
    ///// <param name="blLowerStatus">小类别状态</param>
    //public void SearchGetLowerCategory(string strLowerName, bool blLowerStatus)
    //{
    //    //实例化一个服务
    //    ProductService lowerCategoryManage = new ProductService();

    //    lowerCategoryManage.GetLowerCategoryCompleted += new GetLowerCategoryCompletedEventHandler(lowerCategoryManage_GetLowerCategoryCompleted);

    //    //异步调用获得小类别函数
    //    lowerCategoryManage.GetLowerCategoryAsync(strLowerName, blLowerStatus);
    //}


    ///// <summary>
    ///// 
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //void lowerCategoryManage_GetLowerCategoryCompleted(object sender, GetLowerCategoryCompletedEventArgs e)
    //{
    //    //如果纪录为零，则提示用户商品不存在，反之绑定并显示数据。
    //    if (e.Result.Tables[0].Rows.Count != 0)
    //    {
    //        //绑定数据源到dataSet中
    //        dataSet2 = e.Result;
    //        //调用绑定函数
    //        SmallGridviewBind(dataSet2);

    //    }
    //    else
    //    {
    //        this.lblLowerMessage.Text = "没有你查找的商品类别";
           
    //    }
    //}


    /// <summary>
    /// 点击获得小类别Gridview
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void NextButton_Command(object sender, EventArgs e)
    {
        if (CategoryManageMultiView.ActiveViewIndex == 0)
        {    //      
            CategoryManageMultiView.ActiveViewIndex += 1;
        }        
        else
        {
            throw new Exception("An error occurred.");
        }
    }

    /// <summary>
    /// 点击获得大类别Gridview 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BackButton_Command(object sender, EventArgs e)
    {
        if (CategoryManageMultiView.ActiveViewIndex == 1)
        {  //
            CategoryManageMultiView.ActiveViewIndex -= 1;
        }
        else if (CategoryManageMultiView.ActiveViewIndex == 0)
        {
            CategoryManageMultiView.ActiveViewIndex = 0;
        }
        else
        {
            throw new Exception("An error occurred.");
        }
    }

    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="ds">实例一个数据集</param>
    //private void GridviewBind(DataSet ds)
    //{
    //    try
    //    {
    //        this.gdvBigCategory.DataSource = ds.Tables[0].DefaultView;
    //        this.gdvBigCategory.DataBind();

    //        LblCurrentIndex.Text = "第 " + (this.gdvBigCategory.PageIndex + 1).ToString() + " 页";
    //        LblPageCount.Text = "共 " + gdvBigCategory.PageCount.ToString() + " 页";
    //        LblRecordCount.Text = "总共 " + ds.Tables[0].Rows.Count.ToString() + " 条";
    //        if (ds.Tables[0].Rows.Count == 0)
    //        {
    //            btnFirst.Visible = false;
    //            btnPrev.Visible = false;
    //            btnNext.Visible = false;
    //            btnLast.Visible = false;

    //            LblCurrentIndex.Visible = false;
    //            LblPageCount.Visible = false;
    //            LblRecordCount.Visible = false;

    //            LblNoRecord.Visible = true;
    //        }
    //        else if (gdvBigCategory.PageCount == 1)
    //        {
    //            btnFirst.Visible = false;
    //            btnPrev.Visible = false;
    //            btnNext.Visible = false;
    //            btnLast.Visible = false;
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Response.Write("数据库错误，错误原因：" + ex.Message);
    //        Response.End();
    //    }
    //}

    private void GridViewBindUpperCategory(DataSet ds)
    {
        this.gdvBigCategory.DataSource = ds.Tables[0].DefaultView;
        this.gdvBigCategory.DataBind();
    }

    private void PagingUpperCateogy(int iPageSize, int iPageIndex)
    {
        int iCategoryRows = int.Parse(hdfUpperCategoryRows .Value);

        if (iCategoryRows > 0)
        {
            lblUpperRecordCount.Text = "共" + iCategoryRows.ToString() + "条";

            lblUpperNoRecord.Visible = false;
            lblUpperPageCount.Visible = true;

            int iPages = iCategoryRows / iPageSize;

            if (iCategoryRows % iPageSize != 0)
            {
                iPages += 1;
            }

            lblUpperPageCount.Text = "共" + iPages.ToString() + "页";

            if (iPages > 1)
            {
                btnUpperFirst.Visible = true;
                btnUpperLast.Visible = true;
                btnUpperNext.Visible = true;
                btnUpperPrev.Visible = true;
                //if (iPages == iPageIndex)
                //{
                //    btnLast.Enabled = false;
                //}
            }
            else
            {
                btnUpperPrev.Visible = false;
                btnUpperNext.Visible = false;
                btnUpperLast.Visible = false;
                btnUpperFirst.Visible = false;
            }

            lblUpperCurrentIndex.Text = "第" + iPageIndex.ToString() + "页";
            lblUpperCurrentIndex.Visible = true;
        }

        else
        {
            lblUpperNoRecord.Visible = true;
            lblUpperCurrentIndex.Visible = false;
            lblUpperPageCount.Visible = false;
            lblUpperRecordCount.Visible = false;

            btnUpperFirst.Visible = false;
            btnUpperLast.Visible = false;
            btnUpperNext.Visible = false;
            btnUpperPrev.Visible = false;

        }
    }
    /// <summary>
    /// 翻页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void PagerButtonClickUpperCateogy(object sender, EventArgs e)
    {
        string strPageIndex = lblUpperCurrentIndex.Text.Trim();
        strPageIndex = strPageIndex.Substring(1);
        strPageIndex = strPageIndex.Substring(0, strPageIndex.Length - strPageIndex.LastIndexOf(""));
        int iPageIndex = int.Parse(strPageIndex);

        string strPageCount = lblUpperPageCount.Text.Trim();
        strPageCount = strPageCount.Substring(1);
        strPageCount = strPageCount.Substring(0, strPageCount.Length - strPageCount.LastIndexOf(""));
        int iPageCount = int.Parse(strPageCount);

        string arg = ((LinkButton)sender).CommandArgument.ToString();
        switch (arg)
        {
            case "prev":
                if (iPageIndex > 0)
                {
                    iPageIndex -= 1;
                    if (iPageIndex == 0)
                    {
                        iPageIndex = 1;
                    }
                }
                break;
            case "next":
                if (iPageIndex < iPageCount)
                {
                    iPageIndex += 1;
                }
                break;
            case "last":
                iPageIndex = iPageCount;
                break;
            default:
                iPageIndex = 1;
                break;
        }
        int iPageSize = 10;
        this.GridViewBindUpperCategory (this.categoryManage.GetUpperCategoryForPaging(iPageSize, iPageIndex, string.Empty, string.Empty));
        PagingUpperCateogy(iPageSize, iPageIndex);
    }


    ///// <summary>
    ///// 绑定数据
    ///// </summary>
    ///// <param name="ds">实例一个数据集</param>
    //private void SmallGridviewBind(DataSet ds2)
    //{
    //    try
    //    {
    //        this.gdvSmallCategory .DataSource = ds2.Tables[0].DefaultView;
    //        this.gdvSmallCategory .DataBind();

    //        LblCurrentIndex.Text = "第 " + (this.gdvSmallCategory .PageIndex + 1).ToString() + " 页";
    //        LblPageCount.Text = "共 " + gdvSmallCategory.PageCount.ToString() + " 页";
    //        LblRecordCount.Text = "总共 " + ds2.Tables[0].Rows.Count.ToString() + " 条";
    //        if (ds2.Tables[0].Rows.Count == 0)
    //        {
    //            btnFirst.Visible = false;
    //            btnPrev.Visible = false;
    //            btnNext.Visible = false;
    //            btnLast.Visible = false;

    //            LblCurrentIndex.Visible = false;
    //            LblPageCount.Visible = false;
    //            LblRecordCount.Visible = false;

    //            LblNoRecord.Visible = true;
    //        }
    //        else if (gdvSmallCategory.PageCount == 1)
    //        {
    //            btnFirst.Visible = false;
    //            btnPrev.Visible = false;
    //            btnNext.Visible = false;
    //            btnLast.Visible = false;
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Response.Write("数据库错误，错误原因：" + ex.Message);
    //        Response.End();
    //    }
    //}


    private void GridViewBindLowerCategory(DataSet ds)
    {
        this.gdvSmallCategory.DataSource = ds.Tables[0].DefaultView;
        this.gdvSmallCategory.DataBind();
    }

    private void PagingLowerCategory(int iPageSize, int iPageIndex)
    {
        int iCategoryRows = int.Parse(hdfLowerCategoryRows .Value );

        if (iCategoryRows > 0)
        {
            lblLowerRecordCount.Text = "共" + iCategoryRows.ToString() + "条";

            lblLowerNoRecord.Visible = false;
            lblLowerPageCount.Visible = true;

            int iPages = iCategoryRows / iPageSize;

            if (iCategoryRows % iPageSize != 0)
            {
                iPages += 1;
            }

            lblLowerPageCount.Text = "共" + iPages.ToString() + "页";

            if (iPages > 1)
            {
                btnLowerFirst.Visible = true;
                btnLowerLast.Visible = true;
                btnLowerNext.Visible = true;
                btnLowerPrev.Visible = true;
                //if (iPages == iPageIndex)
                //{
                //    btnLast.Enabled = false;
                //}
            }
            else
            {
                btnLowerPrev.Visible = false;
                btnLowerNext.Visible = false;
                btnLowerLast.Visible = false;
                btnLowerFirst.Visible = false;
            }

            lblLowerCurrentIndex.Text = "第" + iPageIndex.ToString() + "页";
            lblLowerCurrentIndex.Visible = true;
        }

        else
        {
            lblLowerNoRecord.Visible = true;
            lblLowerCurrentIndex.Visible = false;
            lblLowerPageCount.Visible = false;
            lblLowerRecordCount.Visible = false;

            btnLowerFirst.Visible = false;
            btnLowerLast.Visible = false;
            btnLowerNext.Visible = false;
            btnLowerPrev.Visible = false;

        }
    }
    /// <summary>
    /// 翻页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void PagerButtonClickLowerCategory(object sender, EventArgs e)
    {
        string strPageIndex = lblLowerCurrentIndex.Text.Trim();
        strPageIndex = strPageIndex.Substring(1);
        strPageIndex = strPageIndex.Substring(0, strPageIndex.Length - strPageIndex.LastIndexOf(""));
        int iPageIndex = int.Parse(strPageIndex);

        string strPageCount = lblLowerPageCount.Text.Trim();
        strPageCount = strPageCount.Substring(1);
        strPageCount = strPageCount.Substring(0, strPageCount.Length - strPageCount.LastIndexOf(""));
        int iPageCount = int.Parse(strPageCount);


        string arg = ((LinkButton)sender).CommandArgument.ToString();
        switch (arg)
        {
            case "prev":
                if (iPageIndex > 0)
                {
                   iPageIndex -= 1;
                   if (iPageIndex == 0)
                   {
                       iPageIndex = 1;
                   }
                }
                break;
            case "next":
                if (iPageIndex < iPageCount)
                {
                    iPageIndex += 1;
                }
                break;
            case "last":
                iPageIndex = iPageCount;
                break;
            default:
                gdvSmallCategory.PageIndex = 1;
                break;
        }
        int iPageSize = 10;
        this.GridViewBindLowerCategory (this.categoryManage.GetLowerCategoryForPaging (iPageSize ,iPageIndex ,string.Empty,string.Empty ));
        PagingLowerCategory(iPageSize, iPageIndex);
    }
}
